{{!

  Copyright (c) Meta Platforms, Inc. and affiliates.

  Licensed under the Apache License, Version 2.0 (the "License");
  you may not use this file except in compliance with the License.
  You may obtain a copy of the License at

      http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.

}}
{{> Autogen}}
#pragma once

{{#program:thrift_includes}}
#include  "{{program:include_prefix}}{{program:name}}_fatal_types.h"
{{/program:thrift_includes}}

#include "{{program:include_prefix}}{{program:name}}_types.h"

#include "{{program:include_prefix}}{{program:name}}_fatal.h"

#include <fatal/type/traits.h>
#include <fatal/type/list.h>

namespace {{program:qualified_namespace}} {

namespace __fbthrift_refl {
namespace __fbthrift_refl_impl = ::apache::thrift::detail::reflection_impl;

{{#program:structs}}{{^struct:union?}}
class {{struct:cpp_name}}_struct_traits {
  class __fbthrift_annotations{{^field:fatal_annotations?}} : public __fbthrift_refl_impl::no_annotations{{/field:fatal_annotations?}} {
    class __fbthrift_members {
      {{#struct:fields}}
      {{#field:fatal_annotations?}}
      class __fbthrift_field_{{field:cpp_name}} {
        struct __fbthrift_keys {
          {{#each field:fatal_annotations as |annotation|}}
          {{#let safe_key = (cpp_fatal_string_id annotation.key)}}
          using {{safe_key}} = __fbthrift_strings_{{program:name}}::{{safe_key}};
          {{/each}}
        };

        struct __fbthrift_values {
          {{#each field:fatal_annotations as |annotation|}}
          using {{(cpp_fatal_string_id annotation.key)}} = {{(cpp_render_fatal annotation.value)}};
          {{/each}}
        };

       public:
        using keys = __fbthrift_keys;
        using values = __fbthrift_values;
        using map = ::fatal::list<
            {{#each (array.enumerate field:fatal_annotations with_last=true) as |index annotation last?|}}
            {{#let safe_key = (cpp_fatal_string_id annotation.key)}}
            ::apache::thrift::annotation<keys::{{safe_key}}, values::{{safe_key}}>{{#if (not last?)}},{{/if}}
            {{/each}}
        >;
      };

      {{/field:fatal_annotations?}}
      {{/struct:fields}}
     public:
      {{#struct:fields}}
      {{#field:fatal_annotations?}}
      using {{field:cpp_name}} = ::apache::thrift::reflected_annotations<__fbthrift_field_{{field:cpp_name}}>;
      {{/field:fatal_annotations?}}
      {{^field:fatal_annotations?}}
      using {{field:cpp_name}} = __fbthrift_refl_impl::reflected_no_annotations;
      {{/field:fatal_annotations?}}
      {{/struct:fields}}
    };

    {{#struct:fatal_annotations?}}
    struct __fbthrift_keys {
      {{#each struct:fatal_annotations as |annotation|}}
      {{#let safe_key = (cpp_fatal_string_id annotation.key)}}
      using {{safe_key}} = __fbthrift_strings_{{program:name}}::{{safe_key}};
      {{/each}}
    };

    struct __fbthrift_values {
      {{#each struct:fatal_annotations as |annotation|}}
      using {{(cpp_fatal_string_id annotation.key)}} = {{(cpp_render_fatal annotation.value)}};
      {{/each}}
    };

    {{/struct:fatal_annotations?}}
   public:
    {{#struct:fatal_annotations?}}
    using keys = __fbthrift_keys;
    using values = __fbthrift_values;
    using map = ::fatal::list<
        {{#each (array.enumerate struct:fatal_annotations with_last=true) as |index annotation last?|}}
        {{#let safe_key = (cpp_fatal_string_id annotation.key)}}
        ::apache::thrift::annotation<keys::{{safe_key}}, values::{{safe_key}}>{{#if (not last?)}},{{/if}}
        {{/each}}
    >;
    {{/struct:fatal_annotations?}}
    using members = __fbthrift_members;
  };

  {{#struct:fields}}
  struct __fbthrift_member_{{field:cpp_name}} {
    using owner = {{struct:cpp_fullname}};
    using name = __fbthrift_strings_{{program:name}}::{{field:name_hash}};
    using tag = ::apache::thrift::ident::{{field:cpp_name}};
    using annotations = ::apache::thrift::reflected_annotations<__fbthrift_annotations::members::{{field:cpp_name}}>;
  };
  {{/struct:fields}}

  struct __fbthrift_member {
    {{#struct:fields}}
    using {{field:cpp_name}} = ::apache::thrift::reflected_struct_data_member<__fbthrift_member_{{field:cpp_name}}>;
    {{/struct:fields}}
  };
 public:
  using type = {{struct:cpp_fullname}};
  using name = __fbthrift_strings_{{program:name}}::{{struct:cpp_name}};
  using member = __fbthrift_member;
  using members = ::fatal::list<
      {{#struct:fields}}
      member::{{field:cpp_name}}{{^last?}},{{/last?}}
      {{/struct:fields}}
  >;
  using metadata = ::apache::thrift::detail::type_common_metadata_impl<
      ::apache::thrift::reflected_annotations<__fbthrift_annotations>
  >;
};

{{/struct:union?}}{{/program:structs}}
} // __fbthrift_refl

{{#program:structs}}{{^struct:union?}}
THRIFT_REGISTER_STRUCT_TRAITS({{#struct:extra_namespace}}{{struct:extra_namespace}}::{{/struct:extra_namespace}}{{struct:cpp_name}}, __fbthrift_refl::{{struct:cpp_name}}_struct_traits);
{{/struct:union?}}{{/program:structs}}
} // namespace {{program:qualified_namespace}}
